import router from "@/router";

const LINK_TYPES = {
  LINK_PARAMS: 'LINK_PARAMS'
};

// function setLinkParams (params) {
//   sessionStorage.setItem("LINK_PARAMS", JSON.stringify(params))
// }

// function getLinkParams () {
//   JSON.parse(sessionStorage.getItem("LINK_PARAMS"))
// }

const state = {
  linkParams: {}
};

const mutations = {
  [LINK_TYPES.LINK_PARAMS] (state, linkParams = {}) {
    state.linkParams = linkParams;
  }
};

const actions = {
  async routeLink ({ commit }, kwargs) {
    if (kwargs.target === '_blank') {
      const { href } = router.resolve({
        name: kwargs.link,
      });
      window.open(href, "_blank");
    } else {
      router.push({
        name: kwargs.link,
      });
    }
    commit(LINK_TYPES.LINK_PARAMS, kwargs.query);
  }
};

export default {
  namespaced: true,
  state,
  mutations,
  actions
};